define([
    'angular-sanitize'
], function() {
    var keywordFilter = angular.module('app.filter.keyword', ['ngSanitize']);

    keywordFilter.filter('xKeyword', ['$sce', function($sce) {
        return function(text, keyword) {
            if (text && keyword) {
                text = encodeURIComponent(text);
                keyword = encodeURIComponent(keyword);
                // replace
                var highlight = text.replace(new RegExp(keyword, 'gi'),
                        '<span style="color:whitesmoke;background-color:darkgrey;">$&</span>');
                highlight = decodeURIComponent(highlight);
                return $sce.trustAsHtml(highlight);
            }
            return $sce.trustAsHtml(text);
        }
    }]);

    return keywordFilter;
});